package com.bitdf.txing.users.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bitdf.txing.users.dao.UserOtherInfoDao;
import com.bitdf.txing.users.entity.UserOtherInfoEntity;
import com.bitdf.txing.users.service.UserOtherInfoService;
import org.springframework.stereotype.Service;


@Service("userOtherInfoService")
public class UserOtherInfoServiceImpl extends ServiceImpl<UserOtherInfoDao, UserOtherInfoEntity> implements UserOtherInfoService {


    /**
     * 修改数量（评论数、关注数等）
     * @param userId
     * @param target
     * @param ops
     * @return
     */
    @Override
    public boolean updateCount(Long userId, String target, int ops) {
        String sql = "";
        switch (target) {
            case "attendCount":
                sql = "attend_count = attend_count";
                break;
            case "fansCount":
                sql = "fans_count = fans_count";
                break;
            case "commentCount":
                sql = "comment_count = comment_count";
                break;
            case "loginCount":
                sql = "login_count = login_count";
                break;
            default:
                return false;
        }
        if (ops == 1) {
            sql += "+";
        } else {
            sql += "-";
        }
        sql = sql + 1;
        UpdateWrapper<UserOtherInfoEntity> wrapper = new UpdateWrapper<>();
        wrapper.lambda().eq(UserOtherInfoEntity::getUserId, userId).setSql(sql);
        boolean update = this.update(wrapper);
        return update;
    }
}